//
//  F_2ViewController.m
//  RACExamale
//
//  Created by cym_bj on 2017/12/4.
//  Copyright © 2017年 com.cym. All rights reserved.
//

#import "F_2ViewController.h"
#import <ReactiveObjc/ReactiveObjC.h>
#import "LoginViewModel.h"
#import "MBProgressHUD+XMG.h"

@interface F_2ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *accounTF;
@property (weak, nonatomic) IBOutlet UITextField *pwdTF;
@property (weak, nonatomic) IBOutlet UIButton *logBtn;

@property (nonatomic,strong)LoginViewModel *loginVM;

@end

@implementation F_2ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"登录";
    
    
    
    self.loginVM=[[LoginViewModel alloc]init];
    RAC(self.loginVM,account)=self.accounTF.rac_textSignal;
    RAC(self.loginVM,pwd)=self.pwdTF.rac_textSignal;
    
    [self.loginVM.loginEnableSiganl subscribeNext:^(id  _Nullable x) {
       
        BOOL enable=[x boolValue];
        self.logBtn.userInteractionEnabled=enable;
        self.logBtn.alpha=enable?1.0f:0.4f;
        
    }];
    
    
    [[self.logBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
       
        [self.loginVM.loginCommand execute:nil];
        
    }];
    
}



@end
